﻿using ManagoMes.Read.API.Applications.SellStockSearchRead;
using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.QRUPC;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace ManagoMes.Read.API.Applications.QRUPCSearch
{
    public class QUCodeBackfillHandler : IRequestHandler<QUCodeBackfillCommand, ResultsDTO<QUCode>>
    {
        private readonly IBateRepository<QUCode> _qucodeRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="qucodeRepository"></param>
        public QUCodeBackfillHandler(IBateRepository<QUCode> qucodeRepository)
        {
            _qucodeRepository = qucodeRepository;
        }
        /// <summary>
        /// 赋码管理详情
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO<QUCode>> Handle(QUCodeBackfillCommand request, CancellationToken cancellationToken)
        {
            DapperHelper dapper = new DapperHelper();
            var conn = dapper.MangoMesRead;
            var list = new ResultsDTO<QUCode>() { Code = 0 };
            var str = "select * from qucode  where QUCodeId=" + request.QUCodeId + "";
            var res = new QUCode();
            list.Data = _qucodeRepository.GetAll(str, res, conn).ToList();
            return list;
        }
    }
}
